home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20010306-20010921 / 000249_fdc@watsun.cc.columbia.edu_Fri Jul 6 11:33:45 EDT 2001.msg < prev    next >
Text File  |  2020-01-01  |  5KB  |  123 lines

  1. Article: 12574 of comp.protocols.kermit.misc
  2. Path: newsmaster.cc.columbia.edu!watsun.cc.columbia.edu!fdc
  3. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  4. Newsgroups: comp.unix.sco.misc,comp.protocols.kermit.misc
  5. Subject: Re: Login Script to Portservers
  6. Date: 6 Jul 2001 15:18:03 GMT
  7. Organization: Columbia University
  8. Lines: 106
  9. Message-ID: <9i4krb$c8u$1@newsmaster.cc.columbia.edu>
  10. References: <4d30cee2.0106290810.737e6c04@posting.google.com> <9hku16$j3a$1@newsmaster.cc.columbia.edu> <Sz617.1532$Tk.35913830@tomcat.sk.sympatico.ca>
  11. NNTP-Posting-Host: watsun.cc.columbia.edu
  12. X-Trace: newsmaster.cc.columbia.edu 994432683 12574 128.59.39.2 (6 Jul 2001 15:18:03 GMT)
  13. X-Complaints-To: postmaster@columbia.edu
  14. NNTP-Posting-Date: 6 Jul 2001 15:18:03 GMT
  15. Xref: newsmaster.cc.columbia.edu comp.unix.sco.misc:135277 comp.protocols.kermit.misc:12574
  16.  
  17. In article <Sz617.1532$Tk.35913830@tomcat.sk.sympatico.ca>,
  18. Don Yakubowski <don_y@tricomp.ca> wrote:
  19. : "Frank da Cruz" <fdc@watsun.cc.columbia.edu> wrote in message
  20. : news:9hku16$j3a$1@newsmaster.cc.columbia.edu...
  21. : > In article <4d30cee2.0106290810.737e6c04@posting.google.com>,
  22. : > Stephen <stephen.young@duron.com> wrote:
  23. : > : I have two Digi Portservers II attached to a SCO 5.05 host server. I
  24. : > : need to write a login script to a the portservers to reboot them
  25. : > : automatically. In contacting Digi I was told there is no way to set up
  26. : > : an auto reboot on the portserver itself and need to write a login
  27. : > : script to accomplish the task. Any help would be appreciated.
  28. : > :
  29. : > You can use C-Kermit, which is (among other things) a Telnet client with
  30. : > built-in scripting:
  31. : >
  32. : >   http://www.columbia.edu/kermit/ckermit.html
  33. : >
  34. : > Scripting tutorials are here:
  35. : >
  36. : >   http://www.columbia.edu/kermit/ckscripts.html
  37. : I have used a sh script that echoed the required commands to a pipe into
  38. : telnet.
  39. : For eg.
  40. :      echo "open your_portserver"
  41. :     sleep 2
  42. :     echo "root"
  43. :     sleep 2
  44. :     echo "portserver_password"
  45. :     sleep 2
  46. :     echo "b a=r"
  47. :     sleep 2
  48. This kind of thing is fine when it works, but it has no possibility of
  49. detecting errors or recovering from them, synchronizing with host prompts
  50. etc (for example, consider that the Password: prompt is usually issued
  51. only after the host flushes any typeahead in its input buffer).  Here's
  52. the corresponding script in C-Kermit:
  53.  
  54.   #!/usr/local/bin/kermit
  55.   set host your_portserver            ; Make the connection
  56.   if fail exit 1 Connection failed    ; Check for failure
  57.   input 10 login:                     ; Wait 10 sec for login prompt
  58.   if fail exit 1 No login prompt      ; Make sure it arrived
  59.   lineout root                        ; Send user ID
  60.   input 5 Password:                   ; Wait 5 sec for Password prompt
  61.   lineout portserver_password         ; Send password
  62.   input 5 >                           ; Wait portserver command prompt
  63.   if fail exit 1 No command prompt    ; Check for failure
  64.   lineout b a=r                       ; Send a command
  65.   ; add more dialog here...
  66.   close                               ; Close the connection
  67.  
  68. About the same number of lines, and you get both synchroniztion and error
  69. detection.  The script does not plow ahead, blindly sending strings to the
  70. host, if some critical step fails.  Every prompt is answered instantly
  71. (the timeout values are a maximum amount of time to wait for the prompt --
  72. obviously you can adjust them -- they are not fixed sleep intervals.)
  73.  
  74. Add a few more lines, and you can get error recovery.  For example, suppose
  75. your port server requires an unpredictable number of carriage returns before
  76. it issues its login prompt.  Replace:
  77.  
  78.   input 10 login:
  79.   if fail exit 1 No login prompt
  80.  
  81. with:
  82.  
  83.   for \%i 1 15 1 {
  84.       lineout                         ; Send a carriage return
  85.       input 10 login:                 ; Wait 10 sec for login prompt
  86.       if success break                ; If we get it breat out of the loop
  87.   }
  88.   if > \%i 15 exit 1 No login prompt
  89.  
  90. Also note that it's not a great idea to store passwords in script files.
  91. You can have your Kermit script prompt you for the password at runtime:
  92.  
  93.   #!/usr/local/bin/kermit
  94.   set host your_portserver
  95.   if fail exit 1 Connection failed
  96.   undefine \%p
  97.   while not defined \%p {
  98.       askq \%p {Portserver Password: }
  99.   }
  100.   for \%i 1 15 1 {
  101.       lineout                         ; Send a carriage return
  102.       input 10 login:                 ; Wait 10 sec for login prompt
  103.       if success break                ; If we get it breat out of the loop
  104.   }
  105.   if > \%i 15 exit 1 No login prompt
  106.   lineout root
  107.   input 5 Password:
  108.   lineout \%p
  109.   input 5 >  ; or whatever the portserver command prompt is
  110.   lineout b a=r
  111.   ; add more dialog here, as much as you want...
  112.   close
  113.  
  114. And so on.  Pretty much any way you can think of to enhance the script,
  115. you can do easily.  For example, suppose the portserver supports Kermit
  116. protocol (as many do) for importing configuration information, patches, etc.
  117. Since it's Kermit executing your script, all it takes is a "send" command
  118. to upload files.
  119.  
  120. - Frank
  121.